/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-23
 * Time: 23:00
 */
class Solution14 {
    public int[] diStringMatch(String s) {
        int n = s.length();

        int[] ret = new int[n+1];

        //用 left 标记最小数 用 right标记最大数
        int left = 0, right = n;
        for(int i = 0; i < n; i++) {
            if(s.charAt(i) == 'I') {
                ret[i] = left;
                left++;
            }else {
                ret[i] = right;
                right--;
            }
        }
        //把最后一个数放进去
        ret[n] = left;
        return ret;
    }
}
